/**
 * ajax post请求
 * */
function ajaxPost(url, postData, successFun, failFun, async) {
	if(!async) {
		async = false;
	} else {
		async = true;
	}
	$.ajax({
		url: url,
		cache: false,
		data: JSON.stringify(postData),
		dataType: 'json', //服务器返回json格式数据
		type: 'POST', //HTTP请求类型
		timeout : 1000, //超时时间设置，单位毫秒
		async: async,
		contentType: "application/json",
		timeout: 10000, //超时时间设置为10秒；
		success: function(res) {
			console.log(res);
			layer.closeAll('loading');
			if(res.success == true) {
				successFun(res);
			} else {
				layer.msg(res.message);
			}
		},
		error: function(res) {
			layer.msg("网络出错……")
		}
	});
}
/**
 * ajax get请求
 * */
function ajaxGet(url, successFun, failFun) {
	$.ajax({
		url: url,
		cache: false,
		dataType: 'json', //服务器返回json格式数据
		type: 'GET', //HTTP请求类型
		timeout : 1000, //超时时间设置，单位毫秒
		contentType: "application/json",
		timeout: 10000, //超时时间设置为10秒；
		success: function(res) {
			console.log(res);
			layer.closeAll('loading');
			if(res.success == true) {
				successFun(res);
			} else {
				layer.msg(res.message);
			}
		},
		error: function(res) {
			layer.msg("网络出错……")
		}
	});
}
var baseUrl = "";
//var baseUrl = "http://dev.gomoretech.com";
//var baseUrl = "http://59.57.252.28:6428";

var _http = {
	/**
	 * 登录接口
	 * */
	handleLogin: function(postData, successFun, failFun) {
		var url = baseUrl + "/palmmall-server/rest/authenticates/tenant-authen";
		ajaxPost(url, postData, successFun, failFun);
	},
	/**
	 * 查询账单
	 * */
	queryBill: function(postData, successFun, failFun) {
		var url = baseUrl + "/palmmall-server/rest/statement/querybycontract";
		ajaxPost(url, postData, successFun, failFun);
	},
	/**
	 * 确认账单
	 * */
	confirmBill: function(postData, successFun, failFun) {
		var url = baseUrl + "/palmmall-server/rest/statement/confirm";
		ajaxPost(url, postData, successFun, failFun);
	},
	/**
	 * 付款接口
	 * */
	chinaPay: function(time, operId, fullname, postData, successFun, failFun) {
		var url = baseUrl + '/palmmall-server/rest/statement/pay?time=' + time + '&operator.operId=' + operId + '&operator.fullname=' + fullname;
		ajaxPost(url, postData, successFun, failFun);
	},
	/**
	 * 查询账单状态
	 * */
	queryStatus: function(billNumber,successFun,failFun){
		var url = baseUrl + "/palmmall-server/rest/statement/getBill/" + billNumber;
		ajaxGet(url, successFun, failFun);
		
	}
}